import api from './index';
import { UserInfo } from './auth';

export interface UserProfile extends UserInfo {
  bio?: string;
  location?: string;
  website?: string;
  socialLinks?: {
    github?: string;
    twitter?: string;
    linkedin?: string;
    [key: string]: string | undefined;
  };
  preferences?: {
    theme?: 'light' | 'dark' | 'system';
    language?: string;
    notification?: boolean;
    [key: string]: any;
  };
}

// 获取用户资料
export const getUserProfile = () => {
  return api.get<any, UserProfile>('/user/profile');
};

// 更新用户资料
export const updateUserProfile = (data: Partial<UserProfile>) => {
  return api.put<any, UserProfile>('/user/profile', data);
};

// 更新用户头像
export const updateUserAvatar = (file: File) => {
  const formData = new FormData();
  formData.append('avatar', file);
  
  return api.post<any, { avatar: string }>('/user/avatar', formData, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
};

// 更新用户密码
export const updateUserPassword = (oldPassword: string, newPassword: string) => {
  return api.put<any, void>('/user/password', { oldPassword, newPassword });
};

// 获取用户统计信息
export const getUserStats = () => {
  return api.get<any, {
    knowledgeCount: number;
    categoryCount: number;
    tagCount: number;
    storageUsed: number;
    storageLimit: number;
  }>('/user/stats');
};